﻿using calculator;
using System;

namespace Tree
{
    /// <summary>
    /// Variable node for storing and retriving symbolic (user) variables
    /// </summary>
    class VarNode : Node
    {
        public VarNode(int id, Store store)
        {
            _id = id;
            _store = store;
        }
        public override double Result
        {
            get
            {
                double x = 0.0;
                if (_store.IsInit(_id))
                    x = _store.Value(_id);
                else
                    Console.WriteLine("Use of uninitialized variable");
                return x;
            }
        }
        public override bool IsLvalue()
        {
            return true;
        }
        public override void Assign(double value)
        {
            _store.SetValue(_id, value);
        }



        private int _id;
        private Store _store;
    }
}
